package field

import "gitee.com/yanwc/net/utils"

// field=13 u2
type (
	VoltageV    float32 // 终端外接电池电压值，量化单位0.1v
	VoltageVRaw [2]byte // 终端外接电池电压值，量化单位0.1v
)

const (
	VoltageVUnit  VoltageV = 0.1 // 量化单位0.1v
	VoltageVRatio uint16   = 10
)

func (v VoltageV) Raw() (out VoltageVRaw) {
	a := uint16(v * VoltageV(VoltageVRatio))
	copy(out[:], utils.NumberToBytesWithBigEndian(a))
	return
}

func (v VoltageVRaw) Type() VoltageV {
	t := utils.BytesToNumber[uint16](v[:])
	return VoltageV(utils.Decimal(float64(VoltageV(t)*VoltageVUnit), 1))
}

func (v VoltageVRaw)Slice() []byte {
	return v[:]
}